package com.aplink.generic.util.objectrule;

import java.io.Serializable;

import android.text.TextUtils;

import com.aplink.generic.constant.type.TargetRuleOperator;
import com.aplink.generic.pojo.GenericObject;

public class Rule implements Serializable {
    private static final long serialVersionUID = -3317362078326625771L;
    private String mColumn;
    private TargetRuleOperator mOperator;
    private String mValue;

    public String getColumn() {
        return this.mColumn;
    }

    public TargetRuleOperator getOperator() {
        return this.mOperator;
    }

    public String getValue() {
        return this.mValue;
    }

    public boolean isValid(final GenericObject genericObject) {
        final String objValue = genericObject.getValue(this.mColumn);
        if (this.mOperator.equals(TargetRuleOperator.EQUAL)) {
            return objValue.equalsIgnoreCase(this.mValue);
        } else if (this.mOperator.equals(TargetRuleOperator.NOT_EQUAL)) {
            return !objValue.equalsIgnoreCase(this.mValue);
        } else if (this.mOperator.equals(TargetRuleOperator.GREATER_THAN)) {

        } else if (this.mOperator.equals(TargetRuleOperator.LESS_THAN)) {

        } else if (this.mOperator.equals(TargetRuleOperator.NULL_OR_EMPTY)) {
            return TextUtils.isEmpty(objValue);
        } else if (this.mOperator
                .equals(TargetRuleOperator.IS_NOT_NULL_OR_EMPTY)) {
            return !TextUtils.isEmpty(objValue);
        }
        return false;
    }

    public void setColumn(final String column) {
        this.mColumn = column;
    }

    public void setOperator(final TargetRuleOperator operator) {
        this.mOperator = operator;
    }

    public void setValue(final String value) {
        this.mValue = value;
    }
}
